package com.pets.controller;

import com.pets.qo.KnowledgeAddQO;
import com.pets.qo.KnowledgeDisAddQO;
import com.pets.service.KnowledgeDisService;
import com.pets.service.KnowledgeService;
import com.pets.util.AjaxLogicBean;
import com.pets.util.PageData;
import com.pets.util.Result;
import com.pets.vo.KnowledgeDisVO;
import com.pets.vo.KnowledgesByPageVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping(value="/knowledgeDis")
public class KnowledgeDisController {
    @Resource
    private KnowledgeDisService knowledgeDisService;
    @Resource
    private KnowledgeService knowledgeService;

    @RequestMapping(value="/selectKnowledgeDisByKid")
    public ModelAndView selectKnowledgeDisByKid(int kId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/user/news_show");
        KnowledgesByPageVO knowledge= knowledgeService.show(kId);
         //System.out.println(knowledge);
        modelAndView.addObject("kshow",knowledge);
        AjaxLogicBean<KnowledgeDisVO> knowledgeDis= knowledgeDisService.getUKnowledgedis(kId);
        modelAndView.addObject("kd",knowledgeDis);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value = "/knowledgeDisAdd")
    public Result knowledgeDisAdd(KnowledgeDisAddQO knowledgeDisAddQO) {
        Result result = knowledgeDisService.KnowledgeDisAddQO(knowledgeDisAddQO);
        return result;
    }
}
